package quickConnect;

import java.util.ArrayList;
import java.util.HashMap;

import javax.swing.JTabbedPane;

import org.quickconnect.ControlObject;

import userInterface.ChatSessionPanel;
import userInterface.MainFrame;

public class DeleteSessionTabVCO implements ControlObject {

	@Override
	public Object handleIt(ArrayList<Object> arg0) {

		if((Boolean) arg0.get(arg0.size()-1)){
			HashMap params = (HashMap) arg0.get(0);
			JTabbedPane tabs = MainFrame.mainFrame.getTabs();
			int indexToRemove = (Integer) params.get("tabsIndex");
			String id = (String)params.get("sessionId");
			tabs.remove(indexToRemove);
			ArrayList<ChatSessionPanel> panels = MainFrame.mainFrame.getChatSessions();
			for(int i =0 ; i< panels.size(); i++){
				if(panels.get(i).getSession().getSessionId().equals(id)){
					MainFrame.mainFrame.getChatSessions().remove(i);
				}
			}
			if(MainFrame.mainFrame.getChatSessions().size() == 0) {
				MainFrame.mainFrame.setSave(false);
			}
		}
		
		return null;
	}

}
